package com.wct.permission.controller;

import com.wct.permission.service.ImageCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author WEI (Email:changtan20000@163.com)
 * @description
 * @date 2020/2/10 15:00
 */
@Controller
public class MainController {

    @Autowired
    private ImageCodeService imageCodeService;

    @RequestMapping("/")
    public String home(){
        return "index";
    }

    @RequestMapping("/index")
    public String index(){
        return "index";
    }


    @RequestMapping("/userLogin")
    public String userLogin(){
        return "sign-in";
    }

    @RequestMapping("/imageCode")
    public void imageCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        ImageIO.write(imageCodeService.createImageCode(request.getSession()), "JPG", response.getOutputStream());
    }
}
